import JSZip from 'jszip'
import JSZipUtils from 'jszip-utils'

function loadZipFileAsync(path: string) {
  return new Promise<ArrayBuffer>((resolve, reject) => {
    JSZipUtils.getBinaryContent(path, function (err, data) {
      if (err) {
        reject(err)
      } else {
        resolve(data)
      }
    })
  })
}
export default function useUnZip() {
  const loadFile = async (path: string) => {
    const data = await loadZipFileAsync(path)
    const res = await JSZip.loadAsync(data)
    const files = res.files
    return files
  }
  return {
    loadFile,
  }
}
